package cn.zzcode.send;

import org.apache.commons.mail.util.MimeMessageParser;
import org.apache.commons.mail.util.MimeMessageUtils;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;
import java.io.IOException;

/**
 * Tile: MailParser
 * Description:
 *
 * @author gexiuyu@dianxiaohuo.net
 * @created 2019/10/22 18:47
 */
public class MailParser {

    public static void main(String[] args) throws Exception {
        File file = new File("D://mail.txt");
        MimeMessage mimeMessage = MimeMessageUtils.createMimeMessage(null, file);
        MimeMessageParser parser = new MimeMessageParser(mimeMessage).parse();
        System.out.println("发件人：" + parser.getFrom());
        System.out.println("主题：" + parser.getSubject());
        System.out.println("收件人：" + parser.getTo());
        System.out.println(parser.parse().getPlainContent());  //结果为空
        System.out.println(parser.parse().getHtmlContent()); //结果为空
    }
}
